<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('讲座报告列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>讲座主题：</label>
                            <input type="text" name="reportTheme" id="reportTheme"/>
                        </li>
                        <li>
                            <label>主办单位：</label>
                            <input type="text" name="hostUnit" id="hostUnit"/>
                        </li>
                        <li>
                            <label>讲座地点：</label>
                            <input type="text" name="reportPlace" id="reportPlace"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="system:report:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <!--                <a class="btn btn-primary single disabled" onclick="$.operate.editTab()" shiro:hasPermission="system:report:edit">-->
            <!--                    <i class="fa fa-edit"></i> 修改-->
            <!--                </a>-->
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="system:report:remove">
                <i class="fa fa-remove"></i> 批量删除
            </a>
            <!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:report:export">-->
            <!--                    <i class="fa fa-download"></i> 导出-->
            <!--                </a>-->
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:report:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:report:remove')}]];
    var socialTitleDatas = [[${@dict.getType('social_title')}]];
    var schoolTitleDatas = [[${@dict.getType('tea_zhicheng')}]];
    var prefix = ctx + "system/report";
    var datas = [[${@dict.getType('sci_report_status')}]];
    var proFlag = [[${@permission.hasPermi('system:report:process')}]];  // 审核
    var infoFlag = [[${@permission.hasPermi('system:report:info')}]];  // 查看
    var checkFlag = [[${@permission.hasPermi('system:report:check')}]];  // 核查
    var jiexiangFlag = [[${@permission.hasPermi('system:report:jiexiang')}]];  // 结项申请

    function getUrl() {
        var year = localStorage.getItem("year");
        return prefix + "/list/" + "?year=" + year;
    }

    $(function () {
        function initTable(options) {
            // 获取当前表格的ID
            // var tableId = options.id;
            // 根据表格ID生成URL
            options.url = getUrl();
            // options.url = getUrl(tableId);
            // 使用生成的选项初始化表格
            $.table.init(options);
        }

        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            detailUrl: prefix + "/detail/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            overUrl: prefix + "/over/{id}", // 结项申请后端路径
            modalName: "讲座报告",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    align: 'center',
                    title: '序号',
                    visible: false
                },
                {
                    field: 'xueyuan',
                    align: 'center',
                    title: '学院'
                },
                {
                    field: 'keyanshi',
                    align: 'center',
                    title: '专业'
                },
                {
                    field: 'teacherName',
                    align: 'center',
                    title: '申请人'
                },

                {
                    field: 'reportTheme',
                    align: 'center',
                    title: '讲座主题'
                },
                {
                    field: 'reportSubject',
                    align: 'center',
                    title: '讲座题目'
                },
                {
                    field: 'hostUnit',
                    align: 'center',
                    title: '主办单位'
                },
                {
                    field: 'reportTime',
                    align: 'center',
                    title: '讲座时间'
                },
                {
                    field: 'reportPlace',
                    align: 'center',
                    title: '讲座地点'
                },
                {
                    field: 'reportNumber',
                    align: 'center',
                    title: '参与人数'
                },
                {
                    field: 'state',
                    title: '申请状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                // {
                //     title: '操作',
                //     align: 'center',
                //     formatter: function(value, row, index) {
                //         var actions = [];
                //         actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                //         actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                //         return actions.join('');
                //     }
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        console.log(row)
                        var actions = [];

                        if (row.state == 1) {
                            if (row.userId == row.uid) {
                                actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                                actions.push('<a   class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>修改</a> ');
                            }

                            actions.push('<a  class="btn btn-success btn-xs ' + proFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.id + '/pro' + '\')"><i class="fa fa-edit"></i>批阅</a> ');
                            // actions.push('<a  class="btn btn-success btn-xs ' + proFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>批阅</a> ');

                        } else if ((row.state == 3 || row.state == 5) && row.userId == row.uid) {
                            actions.push('<a   class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"> <i class="fa fa-edit"></i>更新</a> ');
                        } else if (row.state == 2) {

                            actions.push('<a  class="btn btn-success btn-xs ' + checkFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.id + '/check' + '\')"><i class="fa fa-edit"></i>核查</a> ');
                        } else if (row.state == 4) {
                            if (row.userId == row.uid) {
                                actions.push('<a  class="btn btn-success btn-xs ' + jiexiangFlag + '" href="javascript:void(0)" onclick="$.operate.overTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>申请结项</a> ');
                            }

                            actions.push('<a  class="btn btn-success btn-xs ' + infoFlag + '" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.id + '/info' + '\')"><i class="fa fa-edit"></i>查看</a> ');
                        }
                        return actions.join('');
                    }
                }
            ]
        };
        // $.table.init(options);
        initTable(options);

        // 监听localStorage的变化,当year值改变时，重新初始化表格
        window.addEventListener("storage", function (event) {
            if (event.key === "year") {
                // 销毁表格，再初始化
                $('#bootstrap-table').bootstrapTable('destroy');
                initTable(options)
            }
        })
    });

</script>
</body>
</html>